home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / oop_tp55.zip / ROBOT_A.PAS < prev    next >
Pascal/Delphi Source File  |  1990-02-20  |  3KB  |  92 lines

  1. unit Robot_A;
  2.  
  3. interface
  4.  
  5. uses Graph, Mouse, Crt, RobotSeg;
  6.  
  7. type
  8.  
  9. RobotArm = object( Segment )
  10.            constructor Init( AnchorX, AnchorY, ArmLen : Integer;
  11.                            Position : Degrees;
  12.                            RotStat, DispQ : Boolean );
  13.            procedure MoveTo( APoint : Point; ShowQ : boolean );
  14.            procedure ShowBase;
  15.            procedure ShowLimit; virtual;
  16.            end;
  17.  
  18. implementation
  19.  
  20. constructor RobotArm.Init( AnchorX, AnchorY, ArmLen : Integer;
  21.                          Position : Degrees;
  22.                          RotStat, DispQ : Boolean );
  23. begin
  24.      Segment.Init( AnchorX, AnchorY, ArmLen, Position, RotStat );
  25.      if DispQ = true then
  26.         begin
  27.         Show;
  28.         ShowBase;
  29.         end;
  30. end;
  31.  
  32. procedure RobotArm.MoveTo( APoint : Point; ShowQ : boolean );
  33.  
  34. var D : real;
  35.     RotDelta : integer;
  36.     AxDelta  : integer;
  37. begin
  38.      if RotateQ = true then begin
  39.           RotDelta := 1;
  40.           D := Distance( APoint, BusyEnd );  { find distance }
  41.           Rotate( RotDelta );                  { rotate }
  42.           if D < Distance( APoint, BusyEnd ) then begin
  43.              { if new distance is greater than old distance }
  44.              D := Distance( APoint, BusyEnd ); { set distance }
  45.              RotDelta := -RotDelta;  { reverse direction of rotation }
  46.              Rotate( RotDelta ); { rotate in opposite direction }
  47.              end;
  48.           while D > Distance( APoint, BusyEnd ) do begin
  49.                 { new distance should be less than old }
  50.                 D :=  Distance( APoint, BusyEnd );
  51.                 Rotate( RotDelta );
  52.                 end;
  53.                 { stops when Distance starts to get big again }
  54.           RotDelta := -RotDelta;
  55.           Rotate( RotDelta ); { go back one }
  56.           end;
  57.      AxDelta := 4;
  58.      { set distance }
  59.      D := Distance( APoint, BusyEnd );
  60.      MoveAxial( AxDelta );  { move axially }
  61.      if D < Distance( APoint, BusyEnd ) then begin
  62.         D := Distance( APoint, BusyEnd );
  63.         AxDelta := -AxDelta;
  64.         MoveAxial( AxDelta );
  65.         end;
  66.      while D > Distance( APoint, BusyEnd ) do begin
  67.         D :=  Distance( APoint, BusyEnd );
  68.         MoveAxial( AxDelta );
  69.         end;
  70.      AxDelta := -AxDelta div 2;
  71.      MoveAxial( AxDelta );  { should be here }
  72.      if ShowQ = true then
  73.         begin
  74.         ShowLimit;
  75.         ShowBase;
  76.         end;
  77. end;
  78.  
  79. procedure RobotArm.ShowBase;
  80. begin
  81.      with Anchor do
  82.           Graph.PieSlice(X, Y, 268, 272, Round(GetMaxY/2.2));
  83. end;
  84.  
  85. procedure RobotArm.ShowLimit;
  86. begin
  87.      SetColor( red );
  88.      with Anchor do
  89.           Circle( X, Y, Length );
  90.      SetColor( white );
  91. end;
  92. end.